/***************************************************************************
 *   Copyright (C) 2009 by mj   *
 *   mj_dv@web.de   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/

// installServer.cpp is a part of the steamserverutil project it is the GUI using Qt 4 for the console app steamserverutil
// steamserverutil.googlecode.com

#include <QProcess>

#include "installserver.h"
#include "steamserverutil.h"

installServer::installServer(QWidget *parent) :
    QDialog(parent)

{
    setupUi(this);

    comboBox->insertItems(0, QStringList()
     << "Counter Strike Source"
     << "Day of Defeat Source"
     << "Garrys Mod"
     << "Half Life 2 Death Match"
     << "Team Fortress"
     << "Counter Strike"
     << "Counter Strike Condition Zero"
     << "Death Match Classic"
     << "Day of Defeat"
     << "Opposing Force"
     << "Ricochet"
     << "Team Fortress Classic"
     << "Dark Messiah"
     << "Age of Chivalry"
     << "D.I.P.R.I.P Warm Up (HL2 MOD)"
     << "Synergy (HL2 Mod)"
     << "Zombie Panic: Source (HL2 Mod)"
     << "Enternal Silence (Mod)"
     << "Left 4 Dead");

    connect(installButton, SIGNAL(clicked()), this, SLOT(inst()));
}

void installServer::inst()
{
    statusLabel->setText(tr("Installing! Please wait"));
    installButton->setEnabled(false);

    update();
    repaint();

    steamserverutil *util = new steamserverutil();

    QString c = util->install(comboBox->currentIndex()+1).c_str();

    QProcess *proc = new QProcess(this);

    proc->setWorkingDirectory(util->workdir.c_str());
    proc->execute(c);

    statusLabel->setText(tr("Ready! Server should be installed now"));
    installButton->setEnabled(true);

}
